package com.lwl.blog.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebServlet;

//项目启动的时候将上下文对象放到模板引擎对象
@WebServlet
public class SpringInitListener  implements ServletContextListener {


        @Override
        public void contextInitialized(ServletContextEvent s){
            //1.初始化spring工厂
            ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");

            //2.将工厂放到上下文对象中
            s.getServletContext().setAttribute("spring",context);

        }


}
